'use strict'
const path = require('path')
const webpack = require('webpack')
const defaultSettings = require('./src/settings.js')

function resolve(dir) {
  return path.join(__dirname, dir)
}
const timestamp = new Date().getTime()
// If your port is set to 80,
// use administrator privileges to execute the command line.
// For example, Mac: sudo npm run

// All configuration item explanations can be find in https://cli.vuejs.org/config/
module.exports = {
  publicPath: defaultSettings.isOnlineApp ? defaultSettings.programmeFlag : process.env.NODE_ENV === 'production' ? './' : '/H5/',
  outputDir: defaultSettings.isOnlineApp ? `dist${defaultSettings.programmeFlag}` : 'dist/H5/',
  assetsDir: 'static',
  lintOnSave: true,
  productionSourceMap: false,

  css: {
    loaderOptions: {
      postcss: {
        plugins: [
          require('postcss-px2rem')({
            remUnit: 37.5
          })
        ]
      }
    }
  },

  devServer: {
    publicPath: defaultSettings.isOnlineApp ? defaultSettings.programmeFlag : '/H5/',
    port: '8080',
    open: true,
    disableHostCheck: true,
    overlay: {
      warnings: false,
      errors: true
    },
    proxy: {
      // 以下配置建议不更改
      '/data-dict/app': {
        // target: 'https://qup2dev.quanyou.com.cn/data-dict/api',
        target: 'https://qmpdev.quanyou.com.cn/data-dict/app',
        changeOrigin: true,
        pathRewrite: {
          '^/data-dict/app': ''
        }
      },
      // 以上配置建议不更改
      '/top2-crm/app': {
        target: 'https://qmpdev.quanyou.com.cn/top2-crm',
        // target: 'https://mpanda.quanyou.com.cn/top2-crm',
        // target: `http://192.168.75.222:8558`,
        changeOrigin: true,
        pathRewrite: {
          '^/top2-crm/app': '/app'
        }
      }
    }
  },

  configureWebpack: {
    // provide the app's title in webpack's name field, so that
    // it can be accessed in index.html to inject the correct title.
    plugins: [
      new webpack.DefinePlugin({
        'process.env': {
          QMP_EVN: JSON.stringify(process.env.QMP_EVN)
        }
      })
    ],
    name: defaultSettings.title,
    resolve: {
      alias: {
        '@': resolve('src')
      }
    },
    output: {
      filename: `js/[name].${timestamp}.js`,
      chunkFilename: `js/[name].${timestamp}.js`
    }
  },

  pluginOptions: {
    'style-resources-loader': {
      preProcessor: 'less',
      patterns: [path.resolve(__dirname, './src/styles/index.less')]
    }
  }
}
